/**  
 * @author: suan@unibroad.com
 * @date 2014年5月6日 下午4:10:35
 * @Copyright: 2014 unibroad.com Inc. All rights reserved.
 */
package com.strugglerz.model.common;

import com.strugglerz.model.exception.ParamsException;

/**
 * @Title: PageQuery.java
 * @Package com.unibroad.appstore.model.bizpojo
 * @Description: 分页查询条件
 * @version V1.0
 */
public class PageQuery {

	/**
	 * <code>serialVersionUID</code> - {成员变量描述}.
	 */
	private static final long serialVersionUID = 2848763031889175822L;

	/**
	 * 待查询哪一页数据
	 */
	private int pageNumber;

	/**
	 * 每页查询多少条记录
	 */
	private int pageSize;

	/**
	 * 构造函数.
	 * 
	 * @param page
	 * @param pageSize
	 */
	public PageQuery(int pageNumber, int pageSize) throws ParamsException {
		super();
		if (pageNumber < 0 || pageSize < 1) {
			throw new ParamsException("分页查询条件设置出错");
		}
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
	}

	/**
	 * @return the pageNumber - {返回值描述信息}.
	 */
	public int getPageNumber() {
		return pageNumber < 0 || pageNumber == 0 ? 1 : pageNumber;
	}

	/**
	 * @param pageNumber
	 *            - {参数含义描述}.
	 */
	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	/**
	 * @return the pageSize - {返回值描述信息}.
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize
	 *            - {参数含义描述}.
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 获取起始记录Index, pageNumber
	 * 
	 * @return 起始记录Index
	 */
	public int getOffset() {
		return (pageNumber - 1) * pageSize;
	}

	/**
	 * 获取当前页末尾记录Index
	 * 
	 * @return 当前页末尾记录Index
	 */
	public int getLimit() {
		return pageSize;
	}

}
